package com.arithmetic.search;


import com.arithmetic.sort.SelectSort;

public class BinarySearch {

    public static void main(String[] args) {

        int[] arr = new int[]{1,23,5,7,4,46,7,3};
        int find  = 7;
        SelectSort.selectSort(arr);
        int findVal = binarySearch(arr,0, arr.length- 1, find);
        System.out.println(findVal);
    }

    private static int binarySearch(int[] arr, int left, int right, int findVal){

        if (left > right){
            return -1;
        }
        int mid = (left + right)/2;
        int midVal = arr[mid];
        if(findVal > midVal){
            return binarySearch(arr, mid+ 1, right, findVal);
        }else if(findVal < midVal){
            return binarySearch(arr, left, mid -1, findVal);
        }else {
            return mid;
        }

    }
}
